package com.google.android.material.floatingactionbutton;

import android.animation.Animator.AnimatorListener;
import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.PorterDuff.Mode;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.os.Build.VERSION;
import android.os.Bundle;
import android.os.Parcelable;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.MeasureSpec;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.ImageView.ScaleType;
import androidx.annotation.AnimatorRes;
import androidx.annotation.ColorInt;
import androidx.annotation.DimenRes;
import androidx.annotation.DrawableRes;
import androidx.annotation.IdRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.Px;
import androidx.annotation.RestrictTo;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.coordinatorlayout.widget.CoordinatorLayout.DefaultBehavior;
import androidx.coordinatorlayout.widget.CoordinatorLayout.a;
import androidx.core.view.ViewCompat;
import com.google.android.material.appbar.AppBarLayout;
import com.google.android.material.bottomsheet.BottomSheetBehavior;
import com.google.android.material.internal.VisibilityAwareImageButton;
import com.google.android.material.stateful.ExtendableSavedState;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.List;
import o.aqu.f;
import o.aqu.n;
import o.aqz;
import o.arn;
import o.arq;
import o.arr;
import o.ars;
import o.arw;
import o.asa;
import o.ash;
import o.asi;
import o.ask;
import o.bx;
import o.ce;
import o.gg;
import o.hy;
import o.jd;

@DefaultBehavior(Behavior.class)
public class FloatingActionButton extends VisibilityAwareImageButton implements hy, jd, arn {
    @Nullable
    private Mode ʻ;
    private ColorStateList ʼ;
    private int ʽ;
    private ColorStateList ˊ;
    private int ˊॱ;
    private Mode ˋ;
    private final arr ˋॱ;
    final Rect ˎ;
    @Nullable
    private ColorStateList ˏ;
    private int ˏॱ;
    private final ce ͺ;
    boolean ॱ;
    private final Rect ॱˊ;
    private arq ॱˋ;
    private int ॱॱ;
    private int ᐝ;

    protected static class BaseBehavior<T extends FloatingActionButton> extends androidx.coordinatorlayout.widget.CoordinatorLayout.Behavior<T> {
        private boolean ˊ;
        private c ˋ;
        private Rect ˎ;

        public /* synthetic */ boolean ˋ(CoordinatorLayout coordinatorLayout, View view, View view2) {
            return ˏ(coordinatorLayout, (FloatingActionButton) view, view2);
        }

        public /* synthetic */ boolean ˎ(CoordinatorLayout coordinatorLayout, View view, int i) {
            return ˋ(coordinatorLayout, (FloatingActionButton) view, i);
        }

        public BaseBehavior() {
            this.ˊ = true;
        }

        public BaseBehavior(Context context, AttributeSet attributeSet) {
            super(context, attributeSet);
            TypedArray obtainStyledAttributes = context.obtainStyledAttributes(attributeSet, n.ﹳॱ);
            this.ˊ = obtainStyledAttributes.getBoolean(n.ﾞॱ, true);
            obtainStyledAttributes.recycle();
        }

        public void ˊ(@NonNull a aVar) {
            if (aVar.ʻ == 0) {
                aVar.ʻ = 80;
            }
        }

        public boolean ˏ(CoordinatorLayout coordinatorLayout, FloatingActionButton floatingActionButton, View view) {
            if (view instanceof AppBarLayout) {
                ˋ(coordinatorLayout, (AppBarLayout) view, floatingActionButton);
            } else if (ˋ(view)) {
                ˎ(view, floatingActionButton);
            }
            return false;
        }

        private static boolean ˋ(@NonNull View view) {
            LayoutParams layoutParams = view.getLayoutParams();
            if (layoutParams instanceof a) {
                return ((a) layoutParams).ˋ() instanceof BottomSheetBehavior;
            }
            return false;
        }

        private boolean ॱ(View view, FloatingActionButton floatingActionButton) {
            a aVar = (a) floatingActionButton.getLayoutParams();
            if (!this.ˊ) {
                return false;
            }
            if (aVar.ˎ() != view.getId()) {
                return false;
            }
            if (floatingActionButton.ॱॱ() != 0) {
                return false;
            }
            return true;
        }

        private boolean ˋ(CoordinatorLayout coordinatorLayout, AppBarLayout appBarLayout, FloatingActionButton floatingActionButton) {
            if (!ॱ(appBarLayout, floatingActionButton)) {
                return false;
            }
            if (this.ˎ == null) {
                this.ˎ = new Rect();
            }
            Rect rect = this.ˎ;
            arw.ˏ((ViewGroup) coordinatorLayout, (View) appBarLayout, rect);
            if (rect.bottom <= appBarLayout.ॱॱ()) {
                floatingActionButton.ˊ(this.ˋ, false);
            } else {
                floatingActionButton.ˋ(this.ˋ, false);
            }
            return true;
        }

        private boolean ˎ(View view, FloatingActionButton floatingActionButton) {
            if (!ॱ(view, floatingActionButton)) {
                return false;
            }
            if (view.getTop() < ((a) floatingActionButton.getLayoutParams()).topMargin + (floatingActionButton.getHeight() / 2)) {
                floatingActionButton.ˊ(this.ˋ, false);
            } else {
                floatingActionButton.ˋ(this.ˋ, false);
            }
            return true;
        }

        public boolean ˋ(CoordinatorLayout coordinatorLayout, FloatingActionButton floatingActionButton, int i) {
            List ˏ = coordinatorLayout.ˏ((View) floatingActionButton);
            int size = ˏ.size();
            for (int i2 = 0; i2 < size; i2++) {
                View view = (View) ˏ.get(i2);
                if (!(view instanceof AppBarLayout)) {
                    if (ˋ(view) && ˎ(view, floatingActionButton)) {
                        break;
                    }
                } else if (ˋ(coordinatorLayout, (AppBarLayout) view, floatingActionButton)) {
                    break;
                }
            }
            coordinatorLayout.ˋ(floatingActionButton, i);
            ˋ(coordinatorLayout, floatingActionButton);
            return true;
        }

        public boolean ˎ(@NonNull CoordinatorLayout coordinatorLayout, @NonNull FloatingActionButton floatingActionButton, @NonNull Rect rect) {
            Rect rect2 = floatingActionButton.ˎ;
            rect.set(floatingActionButton.getLeft() + rect2.left, floatingActionButton.getTop() + rect2.top, floatingActionButton.getRight() - rect2.right, floatingActionButton.getBottom() - rect2.bottom);
            return true;
        }

        private void ˋ(CoordinatorLayout coordinatorLayout, FloatingActionButton floatingActionButton) {
            int i = 0;
            Rect rect = floatingActionButton.ˎ;
            if (rect != null && rect.centerX() > 0 && rect.centerY() > 0) {
                int i2;
                a aVar = (a) floatingActionButton.getLayoutParams();
                if (floatingActionButton.getRight() >= coordinatorLayout.getWidth() - aVar.rightMargin) {
                    i2 = rect.right;
                } else if (floatingActionButton.getLeft() <= aVar.leftMargin) {
                    i2 = -rect.left;
                } else {
                    i2 = 0;
                }
                if (floatingActionButton.getBottom() >= coordinatorLayout.getHeight() - aVar.bottomMargin) {
                    i = rect.bottom;
                } else if (floatingActionButton.getTop() <= aVar.topMargin) {
                    i = -rect.top;
                }
                if (i != 0) {
                    ViewCompat.ʽ(floatingActionButton, i);
                }
                if (i2 != 0) {
                    ViewCompat.ॱॱ(floatingActionButton, i2);
                }
            }
        }
    }

    public static class Behavior extends BaseBehavior<FloatingActionButton> {
        public /* bridge */ /* synthetic */ void ˊ(@NonNull a aVar) {
            super.ˊ(aVar);
        }

        public /* bridge */ /* synthetic */ boolean ˋ(CoordinatorLayout coordinatorLayout, FloatingActionButton floatingActionButton, int i) {
            return super.ˋ(coordinatorLayout, floatingActionButton, i);
        }

        public /* bridge */ /* synthetic */ boolean ˎ(@NonNull CoordinatorLayout coordinatorLayout, @NonNull FloatingActionButton floatingActionButton, @NonNull Rect rect) {
            return super.ˎ(coordinatorLayout, floatingActionButton, rect);
        }

        public /* bridge */ /* synthetic */ boolean ˏ(CoordinatorLayout coordinatorLayout, FloatingActionButton floatingActionButton, View view) {
            return super.ˏ(coordinatorLayout, floatingActionButton, view);
        }

        public Behavior(Context context, AttributeSet attributeSet) {
            super(context, attributeSet);
        }
    }

    @RestrictTo({androidx.annotation.RestrictTo.d.LIBRARY_GROUP})
    @Retention(RetentionPolicy.SOURCE)
    public @interface Size {
    }

    public static abstract class c {
        public void ˊ(FloatingActionButton floatingActionButton) {
        }

        public void ॱ(FloatingActionButton floatingActionButton) {
        }
    }

    class d implements ask {
        final /* synthetic */ FloatingActionButton ˎ;

        d(FloatingActionButton floatingActionButton) {
            this.ˎ = floatingActionButton;
        }

        public float ˎ() {
            return ((float) this.ˎ.ᐝ()) / 2.0f;
        }

        public void ˎ(int i, int i2, int i3, int i4) {
            this.ˎ.ˎ.set(i, i2, i3, i4);
            this.ˎ.setPadding(this.ˎ.ˏॱ + i, this.ˎ.ˏॱ + i2, this.ˎ.ˏॱ + i3, this.ˎ.ˏॱ + i4);
        }

        public void ॱ(Drawable drawable) {
            super.setBackgroundDrawable(drawable);
        }

        public boolean ˋ() {
            return this.ˎ.ॱ;
        }
    }

    public FloatingActionButton(Context context) {
        this(context, null);
    }

    public FloatingActionButton(Context context, AttributeSet attributeSet) {
        this(context, attributeSet, o.aqu.d.ॱॱ);
    }

    public FloatingActionButton(Context context, AttributeSet attributeSet, int i) {
        super(context, attributeSet, i);
        this.ˎ = new Rect();
        this.ॱˊ = new Rect();
        TypedArray ॱ = asa.ॱ(context, attributeSet, n.ᵢ, i, f.ʼ, new int[0]);
        this.ˊ = asi.ˊ(context, ॱ, n.ꜞॱ);
        this.ˋ = ash.ˏ(ॱ.getInt(n.ꜝ, -1), null);
        this.ʼ = asi.ˊ(context, ॱ, n.ᐨॱ);
        this.ॱॱ = ॱ.getInt(n.ᶫ, -1);
        this.ʽ = ॱ.getDimensionPixelSize(n.ꓸॱ, 0);
        this.ᐝ = ॱ.getDimensionPixelSize(n.ㆍॱ, 0);
        float dimension = ॱ.getDimension(n.ᴵ, 0.0f);
        float dimension2 = ॱ.getDimension(n.ⁱ, 0.0f);
        float dimension3 = ॱ.getDimension(n.ᶥॱ, 0.0f);
        this.ॱ = ॱ.getBoolean(n.ꜟॱ, false);
        this.ˊॱ = ॱ.getDimensionPixelSize(n.ꞌॱ, 0);
        aqz ॱ2 = aqz.ॱ(context, ॱ, n.ᵔ);
        aqz ॱ3 = aqz.ॱ(context, ॱ, n.ᵎ);
        ॱ.recycle();
        this.ͺ = new ce(this);
        this.ͺ.ˋ(attributeSet, i);
        this.ˋॱ = new arr(this);
        ͺ().ˊ(this.ˊ, this.ˋ, this.ʼ, this.ᐝ);
        ͺ().ˎ(dimension);
        ͺ().ˋ(dimension2);
        ͺ().ˊ(dimension3);
        ͺ().ˎ(this.ˊॱ);
        ͺ().ˋ(ॱ2);
        ͺ().ˏ(ॱ3);
        setScaleType(ScaleType.MATRIX);
    }

    protected void onMeasure(int i, int i2) {
        int ᐝ = ᐝ();
        this.ˏॱ = (ᐝ - this.ˊॱ) / 2;
        ͺ().ॱ();
        ᐝ = Math.min(ˎ(ᐝ, i), ˎ(ᐝ, i2));
        setMeasuredDimension((this.ˎ.left + ᐝ) + this.ˎ.right, (ᐝ + this.ˎ.top) + this.ˎ.bottom);
    }

    public void setRippleColor(@ColorInt int i) {
        setRippleColor(ColorStateList.valueOf(i));
    }

    public void setRippleColor(@Nullable ColorStateList colorStateList) {
        if (this.ʼ != colorStateList) {
            this.ʼ = colorStateList;
            ͺ().ˊ(this.ʼ);
        }
    }

    @Nullable
    public ColorStateList getBackgroundTintList() {
        return this.ˊ;
    }

    public void setBackgroundTintList(@Nullable ColorStateList colorStateList) {
        if (this.ˊ != colorStateList) {
            this.ˊ = colorStateList;
            ͺ().ˋ(colorStateList);
        }
    }

    @Nullable
    public Mode getBackgroundTintMode() {
        return this.ˋ;
    }

    public void setBackgroundTintMode(@Nullable Mode mode) {
        if (this.ˋ != mode) {
            this.ˋ = mode;
            ͺ().ˏ(mode);
        }
    }

    public void setSupportBackgroundTintList(@Nullable ColorStateList colorStateList) {
        setBackgroundTintList(colorStateList);
    }

    @Nullable
    public ColorStateList ˊ() {
        return getBackgroundTintList();
    }

    public void setSupportBackgroundTintMode(@Nullable Mode mode) {
        setBackgroundTintMode(mode);
    }

    @Nullable
    public Mode ॱ() {
        return getBackgroundTintMode();
    }

    public void setSupportImageTintList(@Nullable ColorStateList colorStateList) {
        if (this.ˏ != colorStateList) {
            this.ˏ = colorStateList;
            ʼ();
        }
    }

    @Nullable
    public ColorStateList ˎ() {
        return this.ˏ;
    }

    public void setSupportImageTintMode(@Nullable Mode mode) {
        if (this.ʻ != mode) {
            this.ʻ = mode;
            ʼ();
        }
    }

    @Nullable
    public Mode ˋ() {
        return this.ʻ;
    }

    private void ʼ() {
        Drawable drawable = getDrawable();
        if (drawable != null) {
            if (this.ˏ == null) {
                gg.ʽ(drawable);
                return;
            }
            int colorForState = this.ˏ.getColorForState(getDrawableState(), 0);
            Mode mode = this.ʻ;
            if (mode == null) {
                mode = Mode.SRC_IN;
            }
            drawable.mutate().setColorFilter(bx.ॱ(colorForState, mode));
        }
    }

    public void setBackgroundDrawable(Drawable drawable) {
        Log.i("FloatingActionButton", "Setting a custom background is not supported.");
    }

    public void setBackgroundResource(int i) {
        Log.i("FloatingActionButton", "Setting a custom background is not supported.");
    }

    public void setBackgroundColor(int i) {
        Log.i("FloatingActionButton", "Setting a custom background is not supported.");
    }

    public void setImageResource(@DrawableRes int i) {
        this.ͺ.ˊ(i);
    }

    public void setImageDrawable(@Nullable Drawable drawable) {
        super.setImageDrawable(drawable);
        ͺ().ˊ();
    }

    void ˋ(c cVar, boolean z) {
        ͺ().ˋ(ˋ(cVar), z);
    }

    public void ˋ(@NonNull AnimatorListener animatorListener) {
        ͺ().ˋ(animatorListener);
    }

    public void ˏ(@NonNull AnimatorListener animatorListener) {
        ͺ().ॱ(animatorListener);
    }

    void ˊ(@Nullable c cVar, boolean z) {
        ͺ().ˎ(ˋ(cVar), z);
    }

    public void ˎ(@NonNull AnimatorListener animatorListener) {
        ͺ().ˎ(animatorListener);
    }

    public void ॱ(@NonNull AnimatorListener animatorListener) {
        ͺ().ˏ(animatorListener);
    }

    public boolean ˏ() {
        return this.ˋॱ.ॱ();
    }

    public void setExpandedComponentIdHint(@IdRes int i) {
        this.ˋॱ.ˋ(i);
    }

    public int ʻ() {
        return this.ˋॱ.ˎ();
    }

    public void setUseCompatPadding(boolean z) {
        if (this.ॱ != z) {
            this.ॱ = z;
            ͺ().ˎ();
        }
    }

    public void setSize(int i) {
        this.ʽ = 0;
        if (i != this.ॱॱ) {
            this.ॱॱ = i;
            requestLayout();
        }
    }

    @Nullable
    private o.arq.c ˋ(@Nullable final c cVar) {
        if (cVar == null) {
            return null;
        }
        return new o.arq.c(this) {
            final /* synthetic */ FloatingActionButton ॱ;

            public void ˊ() {
                cVar.ˊ(this.ॱ);
            }

            public void ˋ() {
                cVar.ॱ(this.ॱ);
            }
        };
    }

    public boolean ʽ() {
        return ͺ().ˊॱ();
    }

    public void setCustomSize(@Px int i) {
        if (i < 0) {
            throw new IllegalArgumentException("Custom size must be non-negative");
        }
        this.ʽ = i;
    }

    int ᐝ() {
        return ˋ(this.ॱॱ);
    }

    private int ˋ(int i) {
        if (this.ʽ != 0) {
            return this.ʽ;
        }
        Resources resources = getResources();
        switch (i) {
            case -1:
                if (Math.max(resources.getConfiguration().screenWidthDp, resources.getConfiguration().screenHeightDp) < 470) {
                    return ˋ(1);
                }
                return ˋ(0);
            case 1:
                return resources.getDimensionPixelSize(o.aqu.c.ᐝ);
            default:
                return resources.getDimensionPixelSize(o.aqu.c.ͺ);
        }
    }

    protected void onAttachedToWindow() {
        super.onAttachedToWindow();
        ͺ().ʼ();
    }

    protected void onDetachedFromWindow() {
        super.onDetachedFromWindow();
        ͺ().ʻ();
    }

    protected void drawableStateChanged() {
        super.drawableStateChanged();
        ͺ().ॱ(getDrawableState());
    }

    public void jumpDrawablesToCurrentState() {
        super.jumpDrawablesToCurrentState();
        ͺ().ˏ();
    }

    protected Parcelable onSaveInstanceState() {
        Parcelable extendableSavedState = new ExtendableSavedState(super.onSaveInstanceState());
        extendableSavedState.ˋ.put("expandableWidgetHelper", this.ˋॱ.ˏ());
        return extendableSavedState;
    }

    protected void onRestoreInstanceState(Parcelable parcelable) {
        if (parcelable instanceof ExtendableSavedState) {
            ExtendableSavedState extendableSavedState = (ExtendableSavedState) parcelable;
            super.onRestoreInstanceState(extendableSavedState.ˊ());
            this.ˋॱ.ॱ((Bundle) extendableSavedState.ˋ.get("expandableWidgetHelper"));
            return;
        }
        super.onRestoreInstanceState(parcelable);
    }

    @Deprecated
    public boolean ॱ(@NonNull Rect rect) {
        if (!ViewCompat.ˊᐝ(this)) {
            return false;
        }
        rect.set(0, 0, getWidth(), getHeight());
        ˏ(rect);
        return true;
    }

    public void ˊ(@NonNull Rect rect) {
        rect.set(0, 0, getMeasuredWidth(), getMeasuredHeight());
        ˏ(rect);
    }

    private void ˏ(@NonNull Rect rect) {
        rect.left += this.ˎ.left;
        rect.top += this.ˎ.top;
        rect.right -= this.ˎ.right;
        rect.bottom -= this.ˎ.bottom;
    }

    private static int ˎ(int i, int i2) {
        int mode = MeasureSpec.getMode(i2);
        int size = MeasureSpec.getSize(i2);
        switch (mode) {
            case Integer.MIN_VALUE:
                return Math.min(i, size);
            case 0:
                return i;
            case 1073741824:
                return size;
            default:
                throw new IllegalArgumentException();
        }
    }

    public boolean onTouchEvent(MotionEvent motionEvent) {
        if (motionEvent.getAction() == 0 && ॱ(this.ॱˊ) && !this.ॱˊ.contains((int) motionEvent.getX(), (int) motionEvent.getY())) {
            return false;
        }
        return super.onTouchEvent(motionEvent);
    }

    public void setCompatElevation(float f) {
        ͺ().ˎ(f);
    }

    public void setCompatElevationResource(@DimenRes int i) {
        setCompatElevation(getResources().getDimension(i));
    }

    public void setCompatHoveredFocusedTranslationZ(float f) {
        ͺ().ˋ(f);
    }

    public void setCompatHoveredFocusedTranslationZResource(@DimenRes int i) {
        setCompatHoveredFocusedTranslationZ(getResources().getDimension(i));
    }

    public void setCompatPressedTranslationZ(float f) {
        ͺ().ˊ(f);
    }

    public void setCompatPressedTranslationZResource(@DimenRes int i) {
        setCompatPressedTranslationZ(getResources().getDimension(i));
    }

    public void setShowMotionSpec(aqz o_aqz) {
        ͺ().ˋ(o_aqz);
    }

    public void setShowMotionSpecResource(@AnimatorRes int i) {
        setShowMotionSpec(aqz.ˏ(getContext(), i));
    }

    public void setHideMotionSpec(aqz o_aqz) {
        ͺ().ˏ(o_aqz);
    }

    public void setHideMotionSpecResource(@AnimatorRes int i) {
        setHideMotionSpec(aqz.ˏ(getContext(), i));
    }

    private arq ͺ() {
        if (this.ॱˋ == null) {
            this.ॱˋ = ˊॱ();
        }
        return this.ॱˋ;
    }

    private arq ˊॱ() {
        if (VERSION.SDK_INT >= 21) {
            return new ars(this, new d(this));
        }
        return new arq(this, new d(this));
    }
}
